package com.edu.d2_stream;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo3 {
    /**
     * 收集Stram流，将Stream流转换成，list集合、set集合、数组
     */
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"张无忌","张三","赵敏","张三丰","力气","赵敏");
        Stream<String> Stream = list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3);
        //转换成List集合
        List<String> collect = Stream.collect(Collectors.toList());
        System.out.println(collect);
        //转换成Set集合
        Stream<String> Stream2 = list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3);
        Set<String> set = Stream2.collect(Collectors.toSet());
        System.out.println(set);
        //转换成数组
        Stream<String> Stream3 = list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3);
        Object[] array = Stream3.toArray();
        System.out.println(Arrays.toString(array));
    }
}
